package com.drug.mingkang.controller;
import com.drug.mingkang.model.Discuss;
import com.drug.mingkang.permission.model.PerUsers;
import com.drug.mingkang.service.DiscussService;
import com.drug.mingkang.utils.ResponseMessage;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.UUID;

/**
 * (Discuss)表控制层
 *
 * @author ll
 * @since 2020-09-07 16:13:07
 */
@RestController
@RequestMapping("discuss")
public class DiscussController {
    /**
     * 服务对象
     */
    @Resource
    private DiscussService discussService;


    @Resource
    private  ResponseMessage  responseMessage;
    /**
     * 通过主键查询单条数据
     *
     * @param
     * @return 单条数据
     */
    @PostMapping("selectOne")
    public List<Discuss> selectOne(String  informId) {
        return this.discussService.queryById(informId);
    }


    @PostMapping("insertOn")
    public ResponseMessage insertOn(Discuss  discuss , HttpSession session){
        PerUsers oper = (PerUsers) session.getAttribute("perUsers");
        String now = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));

        System.out.println("取到当前的时间+1"+now);
        discuss.setDiscussId(UUID.randomUUID().toString());
        discuss.setOper(oper.getUserName());
        discuss.setOperImg(oper.getUserImg());
        discuss.setImg(now);
        int rwos = 0;
        rwos  = discussService.insert(discuss);
        if (rwos>0){
            responseMessage.setStatus(1);
            responseMessage.setMessage("回复成功");
        }else {
            responseMessage.setMessage("回复失败  请待会再试");
            responseMessage.setStatus(0);
        }
        return responseMessage;
    }
}